package com.wannengbang.storemobile.homepage;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.wannengbang.storemobile.R;
import com.wannengbang.storemobile.base.BankCardInfoBean;
import com.wannengbang.storemobile.base.BaseActivity;
import com.wannengbang.storemobile.base.DataCallBack;
import com.wannengbang.storemobile.bean.BankInfoBean;
import com.wannengbang.storemobile.bean.StoreListBean;
import com.wannengbang.storemobile.dialog.SelectStoreDialog;
import com.wannengbang.storemobile.event.IncreaseAuthEvent;
import com.wannengbang.storemobile.homepage.adapter.BankAuthListAdapter;
import com.wannengbang.storemobile.homepage.model.HomePageModelImpl;
import com.wannengbang.storemobile.homepage.model.IHomePageModel;
import com.wannengbang.storemobile.utils.ToastUtil;
import com.wannengbang.storemobile.widget.AppTitleBar;

import org.greenrobot.eventbus.Subscribe;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class IncreaseAuthActivity extends BaseActivity {


    @BindView(R.id.title_bar)
    AppTitleBar titleBar;
    @BindView(R.id.tv_card_title)
    TextView tvCardTitle;
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    @BindView(R.id.ll_add_commit)
    LinearLayout llAddCommit;
    private IHomePageModel homePageModel;
    private BankAuthListAdapter listAdapter;
    private List<BankInfoBean.DataBean> beanList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_increase_auth);
        ButterKnife.bind(this);
        registerEventBus();
        initView();
    }

    @Subscribe
    public void onIncreaseAuthEvent(IncreaseAuthEvent event) {
        requestBankInfo();
    }

    public void initView() {
        homePageModel = new HomePageModelImpl();
        beanList = new ArrayList<>();
        listAdapter = new BankAuthListAdapter(beanList);
        recyclerView.setLayoutManager(new LinearLayoutManager(mActivity));
        recyclerView.setAdapter(listAdapter);
        requestBankInfo();
    }


    /**
     * 认证过的列表
     */
    public void requestBankInfo() {
        homePageModel.requestBankInfo(new DataCallBack<BankInfoBean>() {
            @Override
            public void onSuccessful(BankInfoBean bean) {
                beanList.clear();
                beanList.addAll(bean.getData());
                listAdapter.notifyDataSetChanged();
                if (beanList.size() > 0) {
                    tvCardTitle.setVisibility(View.VISIBLE);
                } else {
                    tvCardTitle.setVisibility(View.GONE);
                }
            }

            @Override
            public void onFailed(String msg, String code) {

            }
        });
    }


    @OnClick(R.id.ll_add_commit)
    public void onViewClicked() {
        if (beanList.size() > 0) {
            ToastUtil.showShort("已认证过信用卡");
            return;
        }
        showActivity(AddIncreaseAuthActivity.class);
    }
}
